package com.rran.study.chat.friend.controller;

import com.rran.study.chat.common.base.BaseController;
import com.rran.study.chat.common.model.Response;
import com.rran.study.chat.friend.dto.request.AcceptFriendDTO;
import com.rran.study.chat.friend.dto.request.AddFriendDTO;
import com.rran.study.chat.friend.dto.response.QueryFriendAppListVO;
import com.rran.study.chat.friend.dto.response.QueryFriendsListVO;
import com.rran.study.chat.friend.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yy
 * @Type UserController.java
 * @Desc
 * @date 2020/8/11 10:01
 */
@Api(value = "好友相关")
@RestController
@RequestMapping(value = "/friend", produces = MediaType.APPLICATION_JSON_VALUE)
public class FriendController extends BaseController {

    private static Logger logger = LoggerFactory.getLogger(FriendController.class);

    @Autowired
    private FriendService friendService;


    @ApiOperation(value = "获取好友列表")
    @GetMapping("/friendsList")
    public Response<QueryFriendsListVO> queryFriendsList(@RequestParam String beanId) {
        return friendService.queryFriendsList(beanId);
    }

    @ApiOperation(value = "添加好友")
    @PostMapping("/addFriend")
    public Response addFriend(@Validated @RequestBody AddFriendDTO addFriendDTO, BindingResult bindingResult) {
        checkParameters(bindingResult);
        return friendService.addFriend(addFriendDTO);
    }


    @ApiOperation(value = "接受好友")
    @PostMapping("/acceptFriend")
    public Response<Integer> acceptFriend(@Validated @RequestBody AcceptFriendDTO acceptFriendDTO, BindingResult bindingResult) {
        checkParameters(bindingResult);
        return friendService.acceptFriend(acceptFriendDTO);
    }

    @ApiOperation(value = "获取好友请求记录")
    @GetMapping("/friendApplicationRecords")
    public Response<List<QueryFriendAppListVO>> friendApplicationRecords(@RequestParam String beanId) {
        return friendService.queryFriendAppList(beanId);
    }


}
